package main

import (
	"fmt"
	"time"

	"github.com/psmaoalove/lacheer/src/pkg"
)

func main() {
	var data []interface{}
	var handleErr []interface{}
	pkg.HandleMsg = func(data interface{}, innerData, err chan<- interface{}) {
		// 模拟运行耗时任务
		// time.Sleep(1 * time.Second)
		innerData <- data
		// err <- data
	}

	pkg.Result = func(innerDataCh, errCh <-chan interface{}, stopMsgCh chan<- struct{}) (innerData []interface{}, err []interface{}) {
		go func() {
			for v := range innerDataCh {
				data = append(data, v)
			}
			stopMsgCh <- struct{}{}
		}()
		go func() {
			for l := range errCh {
				handleErr = append(handleErr, l)
			}
			stopMsgCh <- struct{}{}
		}()
		return data, handleErr
	}
	pkg.SendMsg(4, 111*time.Second, func(innerDataCh chan<- interface{}, errCh chan<- interface{}, globalDataCh pkg.GlobalCType) {
		globalDataCh <- 1
		globalDataCh <- 2
		globalDataCh <- 3
		globalDataCh <- 4
		globalDataCh <- 5
		globalDataCh <- 6
	})

	fmt.Printf("data:  %+#v \n", data)
	fmt.Printf("err: %+#v \n", handleErr)
}
